// custom-tab-bar/index.js
import {storeBindingsBehavior} from 'mobx-miniprogram-bindings'
import {store} from '../store/store'

Component({


  options:{
    styleIsolation:'shared'
  },
  behaviors:[storeBindingsBehavior],
  storeBindings:{
    store,
    fields:{
      messageNum:'messageNum',
      carNum:'carNum',
      active:'activeTabBarIndex'
    },
    actions:{
      updateActive:'updateactiveTabBarIndex'
    }
  },

 observers:{
    'messageNum':function(val){
      this.setData({
        'list[1].info':val
      })
    },
    'carNum':function(val){
      this.setData({
        'list[2].info':val
      })
    }
  },

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    "list": [
      {
        "pagePath": "/pages/home/home",
        "text": "首页",
        "iconPath": "/images/tab/home1.png",
        "selectedIconPath": "/images/tab/home.png"
      },
      {
        "pagePath": "/pages/message/message",
        "text": "消息",
        "iconPath": "/images/tab/record.png",
        "selectedIconPath": "/images/tab/record1.png",
        info:''
      },
      /*{
        "pagePath": "/pages/car/car",
        "text": "购物车",
        "iconPath": "/images/tab/record.png",
        "selectedIconPath": "/images/tab/record1.png",
        info:''
      },*/
      {
        "pagePath": "/pages/account/account",
        "text": "账户",
        "iconPath": "/images/tab/account.png",
        "selectedIconPath": "/images/tab/account1.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.setData({ active: event.detail });
      this.updateActive(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})